home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1978 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: compassnet.com!usenet
  2. From: smelly@e-tex.com
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Newbie question:  Is this code OK?
  5. Date: Wed, 17 Jan 1996 23:29:44 -0600
  6. Organization: Compass Net, Inc.
  7. Message-ID: <30FDDAC8.D79@e-tex.com>
  8. References: <4di986$fk1@pegasus.interpac.net>
  9. NNTP-Posting-Host: 206.25.37.101
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b5 (Win95; I)
  14.  
  15. > Do I need the empty {} after a for loop that has no body?  I assumed > 
  16. > if I didn't, the loop would execute the next statement after it.
  17.  
  18.  
  19. >                         for (; i<length, ((string[i]!='\n') &&
  20. >                                 (string[i]!='\t') &&
  21. >                                 (string[i]!=' ')); i++)
  22. >                                  /* and skip past any other */
  23. >                                  /* chars that may be there */
  24. >                         { }     /* loop does all work, nothing inside body */
  25.  
  26. I am also new to C programming; however, I think I can make one 
  27. suggestion.  Since your second for loop does all the work and you don't 
  28. need a body, you can write it like this.
  29.  
  30.                          for ( ; i<length, ((string[i]!='\n') &&
  31.                                  (string[i]!='\t') &&
  32.                                  (string[i]!=' ')); i++);
  33.  
  34. Placing the semi-colon at the end of the loop will prevent it from 
  35. running the next statement following the loop until after it has 
  36. processed to a point where the condition if false.  I believe this will 
  37. work.  Good luck and have fun! :-)
  38.  
  39. smelly@e-tex.com
  40. Smelly Dog
  41.